package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.bean.GradeBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.Set;

@Mapper
public interface IGradeMapper extends BaseMapper<GradeBean> {
    @Select("SELECT distinct ur.fk_userId,g.* FROM t_user_role ur,t_role_grade rg," +
            "t_grade g WHERE ur.fk_roleId = rg.fk_roleId AND " +
            "rg.fk_gradeId = g.pk_gradeId AND ur.fk_userId = #{userId}")
    @ResultMap("gradeMapper")
    Set<GradeBean> findGrades(Integer userId);

    Set<GradeBean> findByRole(@Param("roles") Integer[] roles);

    @Select("SELECT g.* FROM t_role_grade rg,t_grade g WHERE " +
            "rg.fk_gradeId = g.pk_gradeId AND rg.fk_roleId = #{id}")
    @ResultMap("gradeMapper")
    Set<GradeBean> findById(Integer id);

    public Set<GradeBean> findByAll(Integer userId) ;
}
